package com.raccoonagents.tools.cascet2d.model.containers;

import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.GL11;

import com.raccoonagents.tools.cascet2d.interfaces.IGraphicContainer;
import com.raccoonagents.tools.cascet2d.model.Vector2f;
/**
 *  @author Kari Kuvaja
 *  A container class that will clip any element child outside it's dimensions at rendering.
 *
 */
public class ClippingGraphicContainerElement extends AbstractGraphicContainerElement {


	public ClippingGraphicContainerElement(final IGraphicContainer parent, final Vector2f location, final Vector2f size) {
		super(parent, location, size);
	}
	
	/**
	 * will clip any element child outside it's dimensions at rendering.
	 */
	@Override
	public final void render() {
		
		GL11.glPushMatrix();

		// scale to screen size
		final float scaleY = Display.getDisplayMode().getHeight() / size.y;
		final float scaleX = Display.getDisplayMode().getWidth() / size.x;
		
		GL11.glScalef(scaleX,scaleY,0.0f);
		// adjust camera position
		org.lwjgl.opengl.glu.Project.gluLookAt(location.x,location.y, 1, location.x, location.y, 0, 0, 1, 0);
		
		// get new viewport, that is size of the image.
		GL11.glViewport((int)location.x, (int)location.y, (int)size.x, (int)size.y);
		
		super.render();
		
		
		GL11.glPopMatrix();
	}
	/*
	@Override
	public float getWorldRotation(final float rotation) {

		return rotation;
	}*/



	
}
